package com.lottery.utils.playUtils;

import com.lottery.initData.InitData;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class SscPlayUtilNum {
    private Map<Integer,String> niuNiuMap;

    private boolean flag =false;

    private String opencode;

    private Map<String,String> opencodeMap;

    private List<String> opencodeList;

    private String niuNiu;


    public SscPlayUtilNum(String opencode) {
        String aa = null;
        opencodeMap = new HashMap<>();
        opencodeList = new ArrayList<>();
        String[] strings = opencode.split(",");
        //List<Integer> list = new ArrayList<>();
        for (String ss : strings){
            opencodeList.add(ss);
        }
        String zz = opencode.replace(",","");
        for (int i = 0; i < 3; i++) {
//            list = new ArrayList<>();
//            list.add(Integer.parseInt(strings[i]));
//            list.add(Integer.parseInt(strings[i + 1]));
//            list.add(Integer.parseInt(strings[i + 2]));
            switch (i) {
                case 0:
                    aa = "前";
                    break;
                case 1:
                    aa = "中";
                    break;
                case 2:
                    aa = "后";
                    break;
            }
            opencodeMap.put(aa,zz.substring(i,i+3));
        }
        this.opencode = opencode;
    }

    //数字组合玩法(玩法见rule,例如:五星二码36)
    public boolean group(String bet){
        flag=true;
        List<String> remarkList = new ArrayList<>();
       for(String aa :opencodeList){
           remarkList.add(aa);
       }
        String bets = bet.substring(4,bet.length());
        List<String> list = new ArrayList<>();
        for(int i = 0;i<(bets.length());i++){
            list.add(bets.substring(i,i+1));
        }
        for(String ss :list){
            if (!remarkList.contains(ss)){
                flag = false;
                break;
            }else{
                remarkList.remove(ss);
            }

        }
        return flag;
    }

    /**
     *
     *数字定位
     */
    //定位胆(rule:定位胆1/8,1是位置,8是数值)
    public boolean dingWeiDan(String bet){
        flag = false;
        String bets = bet.substring(3,bet.length());
        String[] betList = bets.split("/");
        if(opencodeList.get(Integer.parseInt(betList[0])-1).equals(betList[1])){
            flag = true;
        }
        return flag;
    }

    //前中后三码(rule:前中后三码前345)
    public boolean renSan(String bet){
        flag = false;
        String bets = bet.substring(5,bet.length());
        String position = bets.substring(0,1);
        String num = bets.substring(1,bets.length());
        if(opencodeMap.get(position).equals(num)){
            flag = true;
        }
        return flag;
    }

    //组六复式玩法(组六复式前345)
    public boolean zuLiu(String bet){
        flag =true;
        String bets = bet.substring(4,bet.length());
        String position = bets.substring(0,1);
        String num = bets.substring(1,bets.length());
        List<String> list = new ArrayList<>();
        for(int i = 0;i<(num.length());i++){
            list.add(num.substring(i,i+1));
        }
        List<String> listzz = new ArrayList<>();
        for(int i = 0;i<opencodeMap.get(position).length();i++){
            listzz.add(opencodeMap.get(position).substring(i,i+1));
        }
        for(String ss :list){
            if(!listzz.contains(ss)){
                flag = false;
                break;
            }else {
                listzz.remove(ss);
            }
        }
        return flag;
    }

    //任选二码组合玩法(rule:任选二码组合12)
    public boolean renEr(String bet){
        flag = false;
        //顺序
        String bets = bet.substring(6,bet.length());
        //倒序
        String betDaoxu = bets.substring(1,2)+bets.substring(0,1);

        String rule =opencode.replace(",","");

        if(rule.contains(bets) || rule.contains(betDaoxu)){
            flag = true;
        }
        return flag;
    }

    //前三任选一码玩法(rule:前三任选一码8)
    public boolean renYi(String bet){
        flag = false;
        String bets = bet.substring(6,bet.length());
        if(opencodeMap.get("前").contains(bets)){
            flag =true;
        }
        return flag;
    }


    //数字倍率玩法(rule:一帆风顺8)
    public boolean beiLv(String bet){
        flag =false;
        int a = 100;
        int b = 0;
        String rule = bet.substring(0,4);
        String num = bet.substring(4,5);
        switch (rule){
            case "一帆风顺":
                a=1;
                break;
            case "好事成双":
                a=2;
                break;
            case "三星报喜":
                a=3;
                break;
            case "四季发财":
                a = 4;
                break;
        }
        for(String aa : opencodeList){
            if(aa.equals(num)){
                b++;
            };
        }
        if(b>=a){
            flag = true;
        }
        return flag;
    }

    //龙玩法(rule:龙)
    public boolean longPlay(String bet){
        flag = false;
        if(Integer.parseInt(opencodeList.get(0))>Integer.parseInt(opencodeList.get(4))){
            flag =true;
        }
        return flag;
    }

    //虎玩法(rule:虎)
    public boolean huPlay(String bet){
        flag= false;
        if(Integer.parseInt(opencodeList.get(0))< Integer.parseInt(opencodeList.get(4))){
            flag =true;
        }
        return flag;
    }

    //合玩法(rule :合)
    public boolean hePlay(){
        flag= false;
        if(Integer.parseInt(opencodeList.get(0)) == Integer.parseInt(opencodeList.get(4))){
            flag =true;
        }
        return flag;
    }

    //斗牛(rule :牛牛)
    public boolean douNiu(String bet){
        flag = false;
        if(niuNiu == null){
            this.initNiuNiu();
        }
        if(bet.equals(niuNiu)){
            flag =true;
        }
        return flag;
    }
    //根据开奖号码开出这一期的斗牛
    private void initNiuNiu(){
//        niuNiuMap = new HashMap<>();
//        niuNiuMap.put(1,"牛一");
//        niuNiuMap.put(2,"牛二");
//        niuNiuMap.put(3,"牛三");
//        niuNiuMap.put(4,"牛四");
//        niuNiuMap.put(5,"牛五");
//        niuNiuMap.put(6,"牛六");
//        niuNiuMap.put(7,"牛七");
//        niuNiuMap.put(8,"牛八");
//        niuNiuMap.put(9,"牛九");
//        niuNiuMap.put(0,"牛牛");
//        niuNiuMap.put(-1,"无牛");
        int niuNum = -1;
       List<Integer> list = new ArrayList<>();
       for(String ss : opencodeList){
           list.add(Integer.parseInt(ss));
       }
       int[][] aa  = new int[][]{{0,1,2},{0,1,3},{0,1,4},{0,2,3},{0,2,4},{0,3,4},{1,2,4},{1,2,3},{1,3,4},{2,3,4}};
        for(int[] ss :aa){
            int sum = 0;
            for(int a :ss){
                sum+=list.get(a);
            }
            if(sum %10==0){
                int z = 0;
                for(int a :ss){
                    list.remove(a-z);
                    z++;
                }
                niuNum = (list.get(0)+list.get(1))%10;
                break;
            }
        }
       // niuNiu = niuNiuMap.get(niuNum);
    }




}
